home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / libsrc / c / sys / gettimeo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  1.2 KB  |  57 lines

  1. /*
  2.   (c) Copyright 1992 Eric Backus
  3.  
  4.   This software may be used freely so long as this copyright notice is
  5.   left intact.  There is no warrantee on this software.
  6. */
  7.  
  8. #include <sys/time.h>
  9. #include <dos.h>
  10.  
  11. static int daylight, gmtoffset;
  12.  
  13. int
  14. gettimeofday (struct timeval *tp, struct timezone *tzp)
  15. {
  16.   if (tp)
  17.   {
  18.     struct time t;
  19.     struct date d;
  20.     struct tm tmrec;
  21.  
  22.     gettime (&t);
  23.     getdate (&d);
  24.     tmrec.tm_year = d.da_year - 1900;
  25.     tmrec.tm_mon = d.da_mon - 1;
  26.     tmrec.tm_mday = d.da_day;
  27.     tmrec.tm_hour = t.ti_hour;
  28.     tmrec.tm_min = t.ti_min;
  29.     tmrec.tm_sec = t.ti_sec;
  30.     tmrec.tm_gmtoff = gmtoffset;
  31.     tmrec.tm_isdst = daylight;
  32.     tp->tv_sec = mktime (&tmrec);
  33.     tp->tv_usec = t.ti_hund * (1000000 / 100);
  34.   }
  35.   if (tzp)
  36.   {
  37.     tzp->tz_minuteswest = gmtoffset;
  38.     tzp->tz_dsttime = daylight;
  39.   }
  40.   return 0;
  41. }
  42.  
  43. void
  44. __gettimeofday_init ()
  45. {
  46.   time_t ltm, gtm;
  47.   struct tm *lstm;
  48.  
  49.   daylight = 0;
  50.   gmtoffset = 0;
  51.   ltm = gtm = time (NULL);
  52.   ltm = mktime (lstm = localtime (<m));
  53.   gtm = mktime (gmtime (>m));
  54.   daylight = lstm->tm_isdst;
  55.   gmtoffset = (int)(gtm - ltm) / 60;
  56. }
  57.